<template>
	<view>
		<u-gap></u-gap>
		<view class="number">
			<view class="number-li">
				<view class="number-new">{{totalNumber||0}}</view>
				<view class="text">团队总人数</view>
			</view>
			<view class="number-li">
				<view class="number-new">{{promotionNumber||0}}</view>
				<view class="text">推广人数</view>
			</view>
			<view class="number-li" v-if="current==1">
				<view class="number-new">{{fansNumber||0}}</view>
				<view class="text">总粉丝数</view>
			</view>
			<!-- <view class="">
				<u-count-to bold font-size="60" color="#ffffff" :end-val="totalNumber"></u-count-to>
				
			</view>
			<view class="">推广人数</view> -->
		</view>
		<u-gap></u-gap>
		<u-sticky>
			<u-tabs :list="list" item-width="250" active-color="#FF7E0E" :current="current" @change="change"></u-tabs>
		</u-sticky>
		
		<view class="fir-box" v-if="current == 1">
			<view class="condition" >
				<view class="condition-li" v-for="(item,index) in filterList" :key="index" >
					<view class="con-label" @click="ascendTab(index,'desc',item)" :class="{'active_nav':filterCur==index}">{{item.label}}</view>
					<view class="con-icon" v-if="index!=0">
						<u-icon name="arrow-up-fill" color="#ff4c00" size="20" @click="ascendTab(index,'asc',item)" v-if="curStr=='asc'&&filterCur==index"></u-icon>
						<u-icon name="arrow-up-fill" color="#d7d7d7" size="20" @click="ascendTab(index,'asc',item)" v-else></u-icon>
						<u-icon name="arrow-down-fill" color="#ff4c00" size="20" @click="descendTab(index,'desc',item)"  v-if="curStr=='desc'&&filterCur==index"></u-icon>
						<u-icon name="arrow-down-fill" color="#d7d7d7" size="20" @click="descendTab(index,'desc',item)" v-else></u-icon>
					</view>
				</view>
			</view>
			<view class="search-box">
				<u-icon name="search" color="#d7d7d7" size="30" @click="openStore"></u-icon>
			</view>
		</view>
		
		<u-gap></u-gap>
		<view class="" style="text-align: center;" v-if="loading">
			<u-loading></u-loading>
		</view>
		<u-empty mode="list" :show="data == '' && !loading"></u-empty>
		<view class="list" v-if="data != ''">
			<view class="item" v-for="(item,index) in data" :key="index" @click="current == 1 ? toDetail(item) : ''">
				<u-image :src="item.imgLogo ? imageURL + item.imgLogo || appletImgUrl+'team-head-img.png' : appletImgUrl+'team-head-img.png'"
				 width="98" height="98" shape="circle"></u-image>
				<view class="info">
					<view class="upper">
						<view class="state">{{item.storeName || item.realName || '未认证'}}</view>
						<view class="vip">
							<u-image mode="widthFix" v-if="current != 1" :src="item.userLevel > 1 ? appletImgUrl+'team-vip-icon.png' : appletImgUrl+'team-vip-icon2.png' "
							 width="36"></u-image>
							<u-image mode="widthFix" v-else :src="appletImgUrl+'team-vip-icon.png'" width="36"></u-image>
							<text>{{item.levelName}}</text>
						</view>
					</view>
					<view class="lower">
						<view class="funs-box" v-if="current == 1">
							<view class="left">粉丝：{{item.totalFans}}</view>
							<view class="right">会员：{{item.memberCount}}</view>
						</view>
						<view class="jindu" v-if="current == 1&&item.rewardReachStatus==-1">
							<view class="jindu-one"><view class="text-one">开户奖：</view>
							<view class="pross"><u-line-progress active-color="#FF1C60" height="20" :percent="((item.currentAmount/item.targetAmount)*100).toFixed(2)"></u-line-progress></view></view>
							
						<view class="shuju">进行中 {{item.currentAmount}}/{{item.targetAmount}}</view>
						</view>
						<view class="" v-if="current == 1&&item.rewardReachStatus==0">开户奖：未达标</view>
						<view class="" v-if="current == 1&&item.rewardReachStatus>0">开户奖：已达标</view>
						<view class="">联系电话：{{item.userName}}</view>
						<view class="">注册时间：{{item.regTime || item.addTime}}</view>
						<view class="" v-if="current == 1">地址：{{item.merchantAddress}}</view>
					</view>
				</view>
				<u-tag bg-color="#ffffff" @click="callPhone(item.userName)" color="#FF7E0E" border-color="#FF7E0E" text="拨打" shape="circle" />
			</view>
		</view>
		<block v-if="data != ''">
			<u-gap></u-gap>
			<u-loadmore :status="status"></u-loadmore>
		</block>
		<u-gap></u-gap>
		<u-popup v-model="showSearch" mode="center" width="500rpx">
					<view class="search-input">
						<u-input v-model="storeName" type="text" :border="true" placeholder="请输入店铺名称"/>
						<view class="search-btn" @click="searchStoreKey">确定</view>
					</view>
		</u-popup>
	</view>
</template>

<script>
import {appletImgUrl} from "@/common/config.js"
	export default {
		data() {
			return {
				appletImgUrl:appletImgUrl,
				current: 0,
				loading: true,
				totalNumber: 0,
				imageURL: this.imageURL,
				status: 'loading',
				data: [],
				list: [{
						name: '我的会员'
					}
					
				],
				fansNumber:0,
				promotionNumber:0,
				filterList:[{label:"默认",keyword:""},{label:"注册时间",keyword:"add_time"},{label:"粉丝",keyword:"fans_count"},{label:"会员数",keyword:"member_count"}],
				filterCur:0,
				curStr:"desc",
				showSearch:false,
				valueStore:"",
				sortWord:"",
				sidx:"",
				storeName:""
			};
		},
		onLoad() {
			this.getTeamTotal();
			this.pageNo = 1
			this.getList(res => {
				this.promotionNumber = res.totalPromoteCount;
				this.fansNumber=res.fansCount;
				this.loading = false
				this.data = res.promoteUsers
				this.status = this.data.length < 10 ? 'nomore' : 'loadmore'
			})
		},
		onReachBottom() {
			if (this.status == 'loading' || this.status == 'nomore') return
			this.pageNo++
			this.status = 'loading'
			this.getList(res => {
				if (res.promoteUsers == '' || res.list == '') {
					this.status = 'nomore'
					return
				}
				this.data = this.data.concat(res.promoteUsers || res.list)
				this.status = 'loadmore'
			})
		},
		methods: {
			getTeamTotal(){
				this.$u.get("userservice/myTeamStatics").then(res => {
					 this.totalNumber=res.totalCounts;
				}).catch(error => {
					
				})
			},
			toDetail(item) {
				this.$u.route('/pages/user/myTeamStoreDetail/myTeamStoreDetail', {
					storeId: item.storeId
				})
				uni.setStorageSync('temporaryData',item)
			},
			callPhone(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				})
			},
			change(e) {
				this.current = e
				this.pageNo = 1
				this.loading = true
				this.data = []
				this.getList(res => {
					this.promotionNumber = res.totalPromoteCount || res.totalCount;
					this.fansNumber=res.fansCount;
					this.loading = false
					this.data = res.promoteUsers || res.list
					this.status = this.data.length < 10 ? 'nomore' : 'loadmore'
				})
			},
			getList(callback) {
				let url = ''
				if (this.current == 0) {
					url = 'user/listDirectUser';  //我的会员
					this.sortWord="";
					this.sidx="";
					this.storeName="";
				} else if (this.current == 1) {
					url = 'sellerstoreotherapply/proMchList'  //我的商家
				} else {
					url = 'user/listDirectUserService'  //我的服务商
					this.sortWord="";
					this.sidx="";
					this.storeName="";
				}
				this.$u.post(url, {
					order:this.sortWord,
					sidx:this.sidx,//asc升序,
					storeName:this.storeName,
					pageNo: this.pageNo,
					pageSize: 10
				}).then(res => {
					// console.log(res);
					callback(res)
				}).catch(error => {
					this.loading = false
				})
			},
			ascendTab(index,str,data){
				this.filterCur=index;
				this.curStr=str;
				this.sidx=data.keyword;
				this.sortWord=str;
				this.pageNo = 1
				this.getList(res => {
					this.promotionNumber = res.totalPromoteCount;
					this.fansNumber=res.fansCount;
					this.loading = false
					this.data = res.list
					this.status = this.data.length < 10 ? 'nomore' : 'loadmore'
				})
			},
			descendTab(index,str,data){
				this.filterCur=index;
				this.curStr=str;
				this.sidx=data.keyword;
				this.sortWord=str;
				this.pageNo = 1
				this.getList(res => {
					this.promotionNumber = res.totalPromoteCount;
					this.fansNumber=res.fansCount;
					this.loading = false
					this.data = res.list
					this.status = this.data.length < 10 ? 'nomore' : 'loadmore'
				})
			},
			openStore(){
				this.showSearch=true;
			},
			searchStoreKey(){
				this.pageNo = 1
				this.getList(res => {
					console.log('ppp',res);
					this.promotionNumber = res.totalPromoteCount;
					this.fansNumber=res.fansCount;
					this.loading = false
					this.data = res.list
					this.status = this.data.length < 10 ? 'nomore' : 'loadmore'
					this.storeName="";
				})
				this.showSearch=false;
			}
		}
	}
</script>

<style lang="scss">
	.list {
		background-color: #FFFFFF;
		border-radius: 20rpx;
		padding: 0 30rpx;
		margin: 0 30rpx;

		.item {
			padding: 30rpx 0;
			border-bottom: 1rpx solid #E1E0E0;
			display: flex;
			align-items: center;

			.info {
				flex: 1;
				margin-left: 20rpx;

				.lower {
					margin-top: 20rpx;

					view {
						font-size: 24rpx;
						color: #AAAAAA;
					}
				}

				.upper {
					display: flex;
					align-items: center;

					.state {
						margin-right: 20rpx;
					}

					.vip {
						display: flex;
						border-radius: 18px;
						// height: 36rpx;
						align-items: center;
						background-color: rgba($color: #EFEFEF, $alpha: .6);
						padding: 4rpx 20rpx;

						text {
							font-size: 20rpx;
							margin-left: 10rpx;
						}
					}
				}
			}

			&:last-child {
				border-bottom: none;
			}
		}
	}

	page {
		// box-sizing: border-box;
		background-color: #f7f7f7;
	}

	.number {
		background: linear-gradient(-90deg, #FECE62, #FF7200);
		border-radius: 20rpx;
		text-align: center;
	     display: flex;
		 flex-direction: row;
		 justify-content: space-between;
		padding: 30rpx 0;
		margin: 0 30rpx;
		.number-li{
			width: 50%;
			text-align: center;
			.number-new{
				font-size: 48rpx;
				font-weight: bold;
				color: #fff;
			}
			.text{
				color: #fff;
			}
		}
         
	
	}
	.condition{
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		.condition-li{
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			padding: 10rpx 20rpx;
			.con-label{
				font-size: 28rpx;
				line-height: 76rpx;
				
			}
			.con-icon{
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin-left: 10rpx;
			}
			.active_nav{
				color: #ff4c00;
			}
		}
	}
	.fir-box{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		.search-box{
			width: 100rpx;
			display: flex;
			flex-direction: row;
			justify-content: center;
		}
	}
	.search-input{
		padding: 30rpx 40rpx;
		.search-btn{
			width: 100%;
			height: 70rpx;
			line-height: 70rpx;
			background-color: #2979ff;
			text-align: center;
			color: #fff;
			margin-top: 20rpx;
		}
	}
	
	.jindu{
		.jindu-one{
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			.pross{
				width: 300rpx;
			}
		}
		.shuju{
			padding-left: 100rpx;
			color: #FF1C60;
		}
	}
</style>
